<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='评论管理',active='comments'">
<!-- 评论管理页面 - 管理文章评论 -->
<header th:replace="admin/header::headerFragment(${title},${active})"></header>
<body class="fixed-left">
<div id="wrapper">
    <!-- 引入头部导航 -->
    <div th:replace="admin/header::header-body"></div>
    <div class="content-page">
        <div class="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">评论管理</h4>
                    </div>
                    <div class="col-md-12">
                        <!-- 评论列表表格 -->
                        <table class="table table-striped table-bordered">
                            <thead>
                            <tr>
                                <th>评论内容</th>
                                <th>评论人</th>
                                <th>评论时间</th>
                                <th>评论人邮箱</th>
                                <th>评论人网址</th>
                                <th>评论状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <!-- 遍历评论列表 -->
                            <th:block th:each="comment : ${comments.list}">
                                <tr th:attr="cid=${comment.coid}">
                                    <!-- 评论内容链接到文章 -->
                                    <td>
                                        <a th:href="@{${commons.site_url('/article/')}+${comment.cid}+'#comments'}"
                                           target="_blank" th:utext="${commons.article(comment.content)}"></a>
                                    </td>
                                    <!-- 评论人 -->
                                    <td th:text="${comment.author}"></td>
                                    <!-- 评论时间 -->
                                    <td th:text="${commons.fmtdate(comment.created, 'yyyy-MM-dd HH:mm:ss')}"></td>
                                    <!-- 评论人邮箱 -->
                                    <td th:text="${comment.mail}"></td>
                                    <!-- 评论人网址 -->
                                    <td><a th:href="@{${comment.url}}" target="_blank" th:text="${comment.url}"></a>
                                    </td>
                                    <!-- 评论状态 -->
                                    <td>
                                        <th:block th:if="${comment.status == 'approved'}">
                                            <span class="label label-success">审核通过</span>
                                        </th:block>
                                        <th:block th:if="${comment.status == 'not_audit'}">
                                            <span class="label label-default">未审核</span>
                                        </th:block>
                                    </td>
                                    <!-- 操作按钮 -->
                                    <td>
                                        <!-- 未审核评论显示通过按钮 -->
                                        <th:block th:if="${comment.status == 'not_audit'}">
                                            <a href="javascript:void(0)"
                                               th:onclick="'updateStatus('+${comment.coid}+', approved);'"
                                               class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i
                                                    class="fa fa-trash-o"></i> <span>通过</span></a>
                                        </th:block>
                                        <!-- 删除评论按钮 -->
                                        <a href="javascript:void(0)" th:onclick="'delComment('+${comment.coid}+');'"
                                           class="btn btn-danger btn-sm waves-effect waves-light m-b-5"><i
                                                class="fa fa-trash-o"></i> <span>删除</span></a>
                                    </td>
                                </tr>
                            </th:block>
                            </tbody>
                        </table>
                        <!-- 分页导航 -->
                        <div th:replace="comm/macros :: pageAdminNav(${comments})"></div>
                    </div>
                </div>
                <!-- 引入页脚内容 -->
                <div th:replace="admin/footer :: footer-content"></div>
            </div>
        </div>
    </div>
</div>
<!-- 引入页脚脚本 -->
<div th:replace="admin/footer :: footer"></div>
<script type="text/javascript">
    /* 初始化tale工具对象 */
    var tale = new $.tale();

    /* 删除评论函数 */
    function delComment(coid) {
        tale.alertConfirm({
            title: '确定删除该评论吗?',
            then: function () {
                tale.post({
                    url: '/admin/comments/delete',
                    data: {coid: coid},
                    success: function (result) {
                        if (result && result.success) {
                            tale.alertOkAndReload('评论删除成功');
                        } else {
                            tale.alertError(result.msg || '评论删除失败');
                        }
                    }
                });
            }
        });
    }

    /* 更新评论状态函数 */
    function updateStatus(coid, status) {
        tale.post({
            url: '/admin/comments/status',
            data: {coid: coid, status: status},
            success: function (result) {
                if (result && result.success) {
                    tale.alertOkAndReload('评论状态设置成功');
                } else {
                    tale.alertError(result.msg || '评论设置失败');
                }
            }
        });
    }
</script>
</body>
</html>